using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player_Stats : Entity_Stat
{
    private List<string> buffList = new();
    private Inventory_Player playerInventory;

    protected override void Awake()
    {
        base.Awake();
        playerInventory = GetComponent<Inventory_Player>();
    }

    public bool CanUserBuff(string buffName) => buffList.Contains(buffName) == false;

    public void AppayBuffEffect(BuffEffectData[] buffs,float duration, string buffName)
    {
        if (buffs.Length == 0 || buffs == null)
            return;
        
        StartCoroutine(BuffEffectCo(buffs, duration, buffName));
    }

    private IEnumerator BuffEffectCo(BuffEffectData[] buffs, float duration, string buffName)
    {
        buffList.Add(buffName);

        foreach (var buff in buffs)
            GetStatByType(buff.type).AddModifier(buffName, buff.value);

        yield return new WaitForSeconds(duration);

        foreach (var buff in buffs)
            GetStatByType(buff.type).RemoveModifier(buffName);

        //触发更新UI
        playerInventory.OnTriggerUpdateUI();

        buffList.Remove(buffName);
    }
}
